package com.food.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.food.pojo.Foods;
import com.food.pojo.FoodsDto;
import com.food.result.Result;
import com.food.service.FoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author beixiang
 * @version 1.0
 * @description TODO
 * @date 2023/3/29 14:44
 */
@Api(tags = "美食首页接口")
@RestController
@RequestMapping("/api/food")
@CrossOrigin(origins = "*")
public class FoodController {
    @Autowired
    FoodsService foodsService;

//    /api/food/index/heat/{limit}/{fixed}
    @ApiOperation(value = "获取地区热门美食列表")
    @GetMapping("/index/heat/{limit}/{fixed}")
    public Result getPopular(@PathVariable Integer limit,@PathVariable String fixed){
        List<Foods> list=foodsService.getPopularList(limit,fixed);
        if(list.isEmpty())
        {
            return Result.fail("查找数据为空");
        }
        return Result.ok(list);
    }

    @ApiOperation(value = "根据用户的行为特征基于UserCF算法进行美食推荐")
    @PostMapping("/index/Recommendation")
    public Result selectRecommendation(@RequestParam("fixed") String fixed){
        List<Foods> foods = foodsService.selectRecommendation(17, fixed);
        return Result.ok(foods);
    }

    /**
     * 查询当前美食下的所有评论以及详情信息
     * @param foodId
     * @return
     */
//    /api/food/detailed/{foodId}
    @ApiOperation(value = "获取美食详情")
    @GetMapping("/detailed/{foodId}")
    public Result getDetails(@PathVariable Integer foodId){
        FoodsDto food=foodsService.getDetailsList(foodId);

        return Result.ok(food);
    }

    //    /api/food/index/recommend

    /**
     * data:{
     * "fixed":"定位"，
     * "type":"类型"，
     * "star"："星级"，
     * "sort"：“排序方式",
     * "page":"当前页",
     * "limit":"每页条数",
     * }
     * @param
     * @return
     */
    @ApiOperation(value = "获取地区特色美食列表")
    @PostMapping ("/index/recommend")
    public Result getRecommend(@RequestParam("fixed") String fixed,
                               @RequestParam("type") String type,
                               @RequestParam("star") Double star,
                               @RequestParam("sort") String sort,
                               @RequestParam("page") Integer page,
                               @RequestParam("limit") Integer limit){


        Page<Foods> list=foodsService.getRecommend(fixed,type,star,sort,page,limit);
        return Result.ok(list);
    }

    /**
     * data:{
     * "fixed":"定位"，
     * "type":"类型"，
     * "star"："星级"，
     * "sort"：“排序方式",
     * "keyword":"搜索内容",
     * }
     * @param
     * @return
     */
    @ApiOperation(value = "搜索地区美食列表")
    @PostMapping ("/index/search")
    public Result getSearch(@RequestParam("fixed") String fixed,
                               @RequestParam("type") String type,
                               @RequestParam("star") Double star,
                               @RequestParam("sort") String sort,
                               @RequestParam("keyword") String keyword,
                              @RequestParam("page") Integer page,
                              @RequestParam("limit") Integer limit
                              ){
        if(keyword=="")
        {
            return Result.fail("搜索内容不能为空");
        }
        Page<Foods> list=foodsService.getSearch(fixed,type,star,sort,keyword,page, limit);
        return Result.ok(list);
    }
}
